//
//  TestListBaseView.m
//  JXCategoryView
//
//  Created by jiaxin on 2018/8/27.
//  Copyright © 2018年 jiaxin. All rights reserved.
//

#import "MHCommonTableBoxView.h"
#import "MHDataSource.h"
#import "UIScrollView+MHRefresh.h"
@interface MHCommonTableBoxView()<DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>


@end

@implementation MHCommonTableBoxView

- (instancetype)initWithFrame:(CGRect)frame dataSource:(MHDataSource *)dataSource
{
    self = [super initWithFrame:frame];
    if (self) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
        self.tableView.backgroundColor = [UIColor whiteColor];
        self.tableView.tableFooterView = [UIView new];
        self.dataSource = dataSource;
        dataSource.tableView = self.tableView;
        self.pageIndex = 1;
        self.perPage = 8;
        __weak __typeof(self)weakSelf = self;
        dataSource.didScrollBlock = ^(UIScrollView *scrollView) {
            if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(listViewDidScroll:)]) {
                [weakSelf.delegate listViewDidScroll:scrollView];
            }
        };

        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        [self addSubview:self.tableView];
        self.tableView.emptyDataSetSource = self;
        self.tableView.emptyDataSetDelegate = self;
        
    }
    return self;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    self.tableView.frame = self.bounds;
    
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIImage imageNamed:@"globle_emptyData"];
}


- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIColor whiteColor];
}


- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    NSString *text = @"暂无音乐数据";
    
    NSDictionary *attributes = @{NSFontAttributeName: MHRegularFont_15,
                                 NSForegroundColorAttributeName: MHMetionTextColor};
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}


- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
    
        return -190/2.0f;
}

- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    
    
    //    id dataSouce =  self.viewModel.dataSource;
    //    if ([self.viewModel.dataSource.lastObject isKindOfClass:[MHCommonGroupViewModel class]]) {
    //       MHCommonGroupViewModel *group = [(NSArray *)self.viewModel.dataSource lastObject];
    //        return group.itemViewModels == nil;
    //    }
    return self.dataSource.items == nil || [self.dataSource.items isEqual:@[]];
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}

#pragma mark - JXPagingViewListViewDelegate

- (UIScrollView *)listScrollView {
    return self.tableView;
}




@end
